package com.example.controller;

import com.example.model.UserInfoResponse;
import com.example.model.UserLoginResponse;
import com.example.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: bjc
 * Date: 2025-08-03
 * Time: 20:28
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 登录
     * @param userName
     * @param password
     * @return
     */
    @RequestMapping("/login")
    public UserLoginResponse login(String userName, String password) {
        log.info("用户登录，userName:{},password:{}", userName, password);
        return userService.login(userName, password);
    }
    /**
     * 注册
     * @param userName
     * @param password
     * @param githubUrl
     * @return
     */
    @RequestMapping("/register")
    public Boolean register(String userName, String password, String githubUrl) {
        log.info("用户注册，userName:{},password:{},githubUrl:{}", userName, password, githubUrl);
        return userService.register(userName, password, githubUrl);
    }
    /**
     * 博客列表页，获取用户信息
     * @param userId
     * @return
     */
    @RequestMapping("/getUserInfo")
    public UserInfoResponse getUserInfo(Integer userId){
        return userService.getUserInfo(userId);

    }
    /**
     * 博客详情页，获取用户信息
     * @param blogId
     * @return
     */
    @RequestMapping("/getAuthorInfo")
    public UserInfoResponse getAuthorInfo(Integer blogId){
        return userService.getAuthorInfoByBlogId(blogId);

    }

}
